﻿// *********************************************************************
// [DCOM Productions]
// [Copyright (C) DCOM Productions All rights reserved.]
// *********************************************************************

namespace BitFlex.Windows.Forms.Design {
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.ComponentModel.Design;
    using System.ComponentModel;
    using System.Windows.Forms.Design;
    using System.Windows.Forms;

    /// <summary>
    /// DesignerActionList for <see cref="BitFlex.Windows.Forms.Design.WizardPageDesigner"/>
    /// </summary>
    public class WizardPageActionList : DesignerActionList, ITypeDescriptorContext, IWindowsFormsEditorService {
        /// <summary>
        /// Initializes a new instance of the BitFlex.Windows.Forms.Design.WizardPageActionList class
        /// </summary>
        /// <param name="component">The base component</param>
        public WizardPageActionList(IComponent component) 
            : base(component) {
            m_HostService = component.Site.GetService(typeof(IDesignerHost)) as IDesignerHost;
            m_ComponentService = component.Site.GetService(typeof(IComponentChangeService)) as IComponentChangeService;
        }

        #region Fields

        private IDesignerHost m_HostService;
        private IComponentChangeService m_ComponentService;

        #endregion

        #region Methods

        public override DesignerActionItemCollection GetSortedActionItems() {
            DesignerActionItemCollection collection = new DesignerActionItemCollection();
            collection.Add(new DesignerActionMethodItem(this, "ViewFirst", "View First", true));
            collection.Add(new DesignerActionMethodItem(this, "ViewNext", "View Next", true));
            collection.Add(new DesignerActionMethodItem(this, "ViewPrevious", "View Previous", true));
            collection.Add(new DesignerActionMethodItem(this, "ViewLast", "View Last", true));
            collection.Add(new DesignerActionHeaderItem("Current WizardPage", string.Empty));
            collection.Add(new DesignerActionMethodItem(this, "RemoveCurrent", "Remove this Page", true));
            return collection;
        }

        private void RemoveCurrent() {
            WizardPage control = Component as WizardPage;
            if (control != null) {
                Wizard owner = control.Parent as Wizard;
                if (owner != null) {
                    owner.Pages.Remove(control);
                }
            }
        }

        private void ViewFirst() {
            WizardPage control = Component as WizardPage;
            if (control != null) {
                Wizard owner = control.Parent as Wizard;
                if (owner != null) {
                    owner.First();
                }
            }
        }

        private void ViewNext() {
            WizardPage control = Component as WizardPage;
            if (control != null) {
                Wizard owner = control.Parent as Wizard;
                if (owner != null) {
                    owner.Next();
                }
            }
        }

        private void ViewPrevious() {
            WizardPage control = Component as WizardPage;
            if (control != null) {
                Wizard owner = control.Parent as Wizard;
                if (owner != null) {
                    owner.Back();
                }
            }
        }

        private void ViewLast() {
            WizardPage control = Component as WizardPage;
            if (control != null) {
                Wizard owner = control.Parent as Wizard;
                if (owner != null) {
                    owner.Last();
                }
            }
        }

        #endregion

        #region ITypeDescriptorContext Members

        IContainer ITypeDescriptorContext.Container {
            get {
                return this.Component.Site.Container;
            }
        }

        object ITypeDescriptorContext.Instance {
            get {
                return this.Component;
            }
        }

        void ITypeDescriptorContext.OnComponentChanged() {
            throw new System.NotImplementedException();
        }

        bool ITypeDescriptorContext.OnComponentChanging() {
            m_ComponentService.OnComponentChanging(this.Component, null);
            return true;
        }

        PropertyDescriptor ITypeDescriptorContext.PropertyDescriptor {
            get {
                throw new System.NotImplementedException();
            }
        }

        #endregion

        #region IServiceProvider Members

        object IServiceProvider.GetService(Type serviceType) {
            if (serviceType.Equals(typeof(IWindowsFormsEditorService))) {
                return this;
            }
            else {
                return m_HostService.GetService(serviceType);
            }
        }

        #endregion

        #region IWindowsFormsEditorService Members

        void IWindowsFormsEditorService.CloseDropDown() {
            throw new NotImplementedException();
        }

        void IWindowsFormsEditorService.DropDownControl(Control control) {
            throw new NotImplementedException();
        }

        DialogResult IWindowsFormsEditorService.ShowDialog(Form dialog) {
            return dialog.ShowDialog();
        }

        #endregion
    }
}
